/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME ttc_proto.h                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2014/09/26 by songbb                               */
/*******************************************************************/

#ifndef __ORA_TTC_PROTO_H_
#define __ORA_TTC_PROTO_H_

#define APM_ORA_SESS_IS_STMT 1
#define APM_ORA_SESS_IS_LOGON 2
#define APM_ORA_SESS_IS_OVERSION 3
#define APM_ORA_SESS_IS_LOB 4
#define APM_ORA_SESS_IS_ODSCRARR 5
#define APM_ORA_SESS_IS_OOPEN 6
#define APM_ORA_SESS_IS_OCLOSE 7
#define APM_ORA_SESS_IS_TEST 8

#define APM_ORA_OACTYPE_DEFINE 1
#define APM_ORA_OACTYPE_BIND 2
#define APM_ORA_OACTYPE_COLUMN 3

#define APM_ORA_PTR 1
#define APM_ORA_NULLPTR 0
#define APM_ORA_PTR_LEN_1 1
#define APM_ORA_PTR_LEN_4 4
#define APM_ORA_PTR_LEN_8 8

/* 向FRdata_field的p_field_name中填充数据时，每个bind的名称，最大长度8，例如 bind1, bind2, bind3 */
#define APM_ORA_BIND_INDEX_NAME_MAXLEN 8
#define APM_ORA_BIND_INDEX_NAME_PREFIX ":"
#define APM_ORA_BIND_NULL "(null)"
#define APM_ORA_BIND_BLOB "(blob)"

typedef enum __em_ttc_code {
    APM_TTC_CODE_TTIPRO = 1,
    APM_TTC_CODE_TTIDTY,
    APM_TTC_CODE_TTIFUN,
    APM_TTC_CODE_TTIOER,
    APM_TTC_CODE_TTIRXH = 6,
    APM_TTC_CODE_TTIRXD,
    APM_TTC_CODE_TTIRPA,
    APM_TTC_CODE_TTISTA,
    APM_TTC_CODE_TTIIOV = 11,
    APM_TTC_CODE_TTIUDS,
    APM_TTC_CODE_TTIOAC,
    APM_TTC_CODE_TTILOBD,
    APM_TTC_CODE_TTIWRN,
    APM_TTC_CODE_TTIDCB,
    APM_TTC_CODE_TTIPFN,
    APM_TTC_CODE_TTIFOB = 19
} TTC_code;

#define ORA_FUN_CODE_OOPEN 2
#define ORA_FUN_CODE_OALL_0303 3
#define ORA_FUN_CODE_OEXEC 4
#define ORA_FUN_CODE_OFETCH 5
#define ORA_FUN_CODE_OCLOSE 8
#define ORA_FUN_CODE_OLOGOFF 9
#define ORA_FUN_CODE_OCOMON 12
#define ORA_FUN_CODE_OCOMOFF 13
#define ORA_FUN_CODE_OCOMMIT 14
#define ORA_FUN_CODE_OROLLBACK 15
#define ORA_FUN_CODE_OCANCEL 20
#define ORA_FUN_CODE_ODSCRARR 43
#define ORA_FUN_CODE_OVERSION 59
#define ORA_FUN_CODE_OK2RPC 67
#define ORA_FUN_CODE_OALL7 71
#define ORA_FUN_CODE_OSQL7 74
#define ORA_FUN_CODE_O3LOGON 81
#define ORA_FUN_CODE_O3LOGA 82
#define ORA_FUN_CODE_OKOD 92
#define ORA_FUN_CODE_OALL8 94
#define ORA_FUN_CODE_OLOBOPS 96
#define ORA_FUN_CODE_ODNY 98
#define ORA_FUN_CODE_OTXSE 103
#define ORA_FUN_CODE_OTXEN 104
#define ORA_FUN_CODE_OCCA 105
#define ORA_FUN_CODE_O80SES 107
#define ORA_FUN_CODE_OAUTH 115
#define ORA_FUN_CODE_OSESSKEY 118
#define ORA_FUN_CODE_OCANA 120
#define ORA_FUN_CODE_OAQEQ 121
#define ORA_FUN_CODE_OAQDQ 122
#define ORA_FUN_CODE_OKPN 125
#define ORA_FUN_CODE_OAQLS 126
#define ORA_FUN_CODE_OOTCM 127
#define ORA_FUN_CODE_OAQGPS 132
#define ORA_FUN_CODE_OSCID 135
#define ORA_FUN_CODE_OSPFPPUT 138
#define ORA_FUN_CODE_OKPFC 139
#define ORA_FUN_CODE_OAQXQ 145
#define ORA_FUN_CODE_OPING 147
#define ORA_FUN_CODE_OKEYVAL 154
#define ORA_FUN_CODE_OXSSCS 155
#define ORA_FUN_CODE_OXSSRO 156
#define ORA_FUN_CODE_OXSSPO 157
#define ORA_FUN_CODE_OSESSGET 162
#define ORA_FUN_CODE_OSESSRLS 163
#define ORA_FUN_CODE_OXSNSO 172
#define ORA_FUN_CODE_OXSSYNC 176
//#define ORA_FUN_CODE_OSESSSTATE 176
#define ORA_FUN_CODE_OAPPCONTREPLAY 177
#define ORA_FUN_CODE_OXSNS 178
#define ORA_FUN_CODE_OXSCRE 179
#define ORA_FUN_CODE_OXSATT 180
#define ORA_FUN_CODE_OXSDET 181
#define ORA_FUN_CODE_OXSDES 182
#define ORA_FUN_CODE_OXSSET 183
#define ORA_FUN_CODE_OAQENQ 184
#define ORA_FUN_CODE_OAQDEQ 185
#define ORA_FUN_CODE_OAQEMNDEQ 186
#define ORA_FUN_CODE_OAQNFY 187


/**
* Oracle 数据字段类型
*/
#define ORA_DTY_VARCHAR 1
#define ORA_DTY_NUMBER 2
#define ORA_DTY_VARNUM 6
#define ORA_DTY_LONG 8
// 自定义 ORA_DTY_ROWID2
#define ORA_DTY_ROWID2 11
#define ORA_DTY_DATE 12
#define ORA_DTY_VBI 15
#define ORA_DTY_RAW 23
#define ORA_DTY_LONG_RAW 24
// 自定义 ORA_DTY_ANYTYPE
#define ORA_DTY_ANYTYPE 58
#define ORA_DTY_CHAR 96
#define ORA_DTY_BINARY_FLOAT 100
#define ORA_DTY_BINARY_DOUBLE 101
#define ORA_DTY_RESULT_SET 102
#define ORA_DTY_ROWID 104
#define ORA_DTY_NAMED_TYPE 109
#define ORA_DTY_REF_TYPE 111
#define ORA_DTY_CLOB 112
#define ORA_DTY_BLOB 113
#define ORA_DTY_BFILE 114
#define ORA_DTY_RSET 116
// 自定义 ORA_DTY_NAMED_TYPE2
#define ORA_DTY_NAMED_TYPE2 121
#define ORA_DTY_TIMESTAMP 180
#define ORA_DTY_TIMESTAMPTZ 181
#define ORA_DTY_INTERVALYM 182
#define ORA_DTY_INTERVALDS 183
#define ORA_DTY_UROWID 208
#define ORA_DTY_TIMESTAMPLTZ 231
#define ORA_DTY_XMLTYPE 257
#define ORA_DTY_DML_RETURN_PARAM 994
#define ORA_DTY_NULL_TYPE 995
#define ORA_DTY_SET_CHAR_BYTES 996
#define ORA_DTY_T2S_OVERLONG_RAW 997
#define ORA_DTY_PLSQL_INDEX_TABLE 998
#define ORA_DTY_FIXED_CHAR 999

/**
* Java 内部数据字段类型
*/
#define ORA_JDBCTYPE_INTERVALDS -104
#define ORA_JDBCTYPE_INTERVALYM -103
#define ORA_JDBCTYPE_TIMESTAMPLTZ -102
#define ORA_JDBCTYPE_TIMESTAMPTZ -101
#define ORA_JDBCTYPE_TIMESTAMPNS -100
#define ORA_JDBCTYPE_LONGNVARCHAR -16
#define ORA_JDBCTYPE_NCHAR -15
#define ORA_JDBCTYPE_PLSQL_INDEX_TABLE -14
#define ORA_JDBCTYPE_BFILE -13
#define ORA_JDBCTYPE_CURSOR -10
#define ORA_JDBCTYPE_NVARCHAR -9
#define ORA_JDBCTYPE_ROWID -8
#define ORA_JDBCTYPE_BIT -7
#define ORA_JDBCTYPE_TINYINT -6
#define ORA_JDBCTYPE_BIGINT -5
#define ORA_JDBCTYPE_LONGVARBINARY -4
#define ORA_JDBCTYPE_VARBINARY -3
#define ORA_JDBCTYPE_RAW -2
#define ORA_JDBCTYPE_LONGVARCHAR -1
#define ORA_JDBCTYPE_NULL 0
#define ORA_JDBCTYPE_CHAR 1
#define ORA_JDBCTYPE_NUMERIC 2
#define ORA_JDBCTYPE_DECIMAL 3
#define ORA_JDBCTYPE_INTEGER 4
#define ORA_JDBCTYPE_SMALLINT 5
#define ORA_JDBCTYPE_FLOAT 6
#define ORA_JDBCTYPE_REAL 7
#define ORA_JDBCTYPE_DOUBLE 8
#define ORA_JDBCTYPE_VARCHAR 12
#define ORA_JDBCTYPE_BOOLEAN 16
#define ORA_JDBCTYPE_DATALINK 70
#define ORA_JDBCTYPE_DATE 91
#define ORA_JDBCTYPE_TIME 92
#define ORA_JDBCTYPE_TIMESTAMP 93
#define ORA_JDBCTYPE_BINARY_FLOAT 100
#define ORA_JDBCTYPE_BINARY_DOUBLE 101
#define ORA_JDBCTYPE_FIXED_CHAR 999
#define ORA_JDBCTYPE_OTHER 1111
#define ORA_JDBCTYPE_JAVA_OBJECT 2000
#define ORA_JDBCTYPE_STRUCT 2002
#define ORA_JDBCTYPE_ARRAY 2003
#define ORA_JDBCTYPE_BLOB 2004
#define ORA_JDBCTYPE_CLOB 2005
#define ORA_JDBCTYPE_REF 2006
#define ORA_JDBCTYPE_OPAQUE 2007
#define ORA_JDBCTYPE_JAVA_STRUCT 2008
#define ORA_JDBCTYPE_SQLXML 2009
#define ORA_JDBCTYPE_NCLOB 2011


/**
* RPC调用函数指针
*/
typedef struct __st_ora_rpc_recv
{
    int (*read_RPA)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_BVC)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_IOV)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_RXH)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*process_SLG)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_RXD)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_DCB)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_LOBD)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_IMPLRES)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*process_EOCS)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
    int (*read_OAC)(Conntrack *p_st_conn, L7session_ora *p_st_sess, L7_ora_packet *p_st_ora_packet);
} Ora_rpc_recv;

int ora_ttc_proto_analyze_req(Conntrack *p_st_conn
                            , L7session_ora *p_st_sess
                            , L7_ora_packet *p_st_ora_packet
                            , Frhash_header *p_st_hash_report);

int ora_ttc_proto_analyze_resp(Conntrack *p_st_conn
                            , L7session_ora *p_st_sess
                            , L7_ora_packet *p_st_ora_packet
                            , Frhash_header *p_st_hash_report
                            , Apm_packet *p_st_packet);

#endif
